package com.ziyun.pop.modules.mercharReport.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ziyun.pop.common.e.mercharReport.FinanceStatus;
import com.ziyun.pop.common.e.mercharReport.ProductionStatus;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.modules.mercharReport.dao.OrderProductItemsDetailDao;
import com.ziyun.pop.modules.mercharReport.entity.MercharProductVO;
import com.ziyun.pop.modules.mercharReport.entity.OrderProductItemsDetailEntity;
import com.ziyun.pop.modules.mercharReport.service.OrderProductItemsDetailService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("orderProductItemsDetailService")
public class OrderProductItemsDetailServiceImpl extends ServiceImpl<OrderProductItemsDetailDao, OrderProductItemsDetailEntity> implements OrderProductItemsDetailService {
    @Autowired
    private OrderProductItemsDetailDao orderProductItemsDetailDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<OrderProductItemsDetailEntity> page = (Page<OrderProductItemsDetailEntity>) this.page(
                new Query<OrderProductItemsDetailEntity>(params).getPage(),
                new QueryWrapper<OrderProductItemsDetailEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R list(Map<String, Object> params) {
        Page<MercharProductVO> page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List<MercharProductVO> list = orderProductItemsDetailDao.list(page, params);
        page.setRecords(list);
        PageUtils pageUtils = new PageUtils(page);
        // 存放枚举类到userdata
        Map<String, List> mapEnum = new HashMap<>();
        List<Map<String, Object>> supplierList = orderProductItemsDetailDao.getSupplier();
        mapEnum.put("supplierList", supplierList); //外协商集合
        mapEnum.put("productionStatus", JsonUtils.enumToList(ProductionStatus.class)); //生产状态
        mapEnum.put("financeStatus", JsonUtils.enumToList(FinanceStatus.class)); //财务审核状态
        return R.ok().put("page", pageUtils).put("userData", mapEnum);
    }

    @Override
    public List<MercharProductVO> exportExcel(Map<String, Object> params) {
        return orderProductItemsDetailDao.list(params);
    }


}
